<template>
	<view class="container">
		<view class="card-view" v-for="(item,index) in articleList" :key="index">
			<uni-card class="card" @click="navTo(item)" :padding="0" :margin="0" :cover="item.imgUrl[0]">
			</uni-card>
			<text>标题:{{item.title}}</text>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				articleList: [{
					imgUrl: [],
					title: "",
					content: "",
				}],
			};
		},
		onLoad() {
			let that = this;
			uni.request({
				url: "http://localhost:8090/article/getHome",
				method: "GET",
				success(res) {
					let list1 = res.data.data;
					let list2 = [];
					for (let item of list1) {
						let str = item.pictures
						let Pictures_url_arr = str.split(">>>");
						let imgUrl = []
						for (let item of Pictures_url_arr.slice(0, -1)) {
							imgUrl.push("http://192.168.31.77:80/app/img/" + item)
						}
						list2.push({
							imgUrl: imgUrl,
							title: item.title,
							content: item.content,
						})
					}
					that.articleList = list2;
				}
			})
		},
		methods: {
			navTo(item) {
				uni.navigateTo({
					url: "/pages/home/advertise",
					success: (res) => {
						res.eventChannel.emit("navToAdvertise", item)
					}
				})
			}
		},
	};
</script>

<style lang="scss" scoped>
	.container {
		display: flex;
		flex-direction: row;
		align-content: space-around;
		flex-wrap: wrap;
	}

	.card-view {
		width: 49%;

	}
</style>